package com.gzy.xuexiziliao.controller;


import com.gzy.xuexiziliao.common.result.Result;
import com.gzy.xuexiziliao.pojo.entity.HealthRecords;
import com.gzy.xuexiziliao.service.HealthRecordsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 健康记录控制类
 */
@RestController
@Slf4j
@RequestMapping("/hc")
public class HealthRecordsController {
    @Autowired
    private HealthRecordsService healthRecordsService;


    /**
     * 新增健康记录
     * @param hr
     * @return
     */
    @PostMapping("/add")
    public Result save(@RequestBody HealthRecords hr){
        log.info("新增健康,hr:{}",hr);
        healthRecordsService.save(hr);
        return Result.success("添加成功");
    }

    //查看健康记录
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("查询健康记录,id:{}",id);
        HealthRecords healthRecords = healthRecordsService.getById(id);
        return Result.success(healthRecords);
    }
    // 上传健康记录
    //修改健康记录
    @PutMapping
    public Result update(@RequestBody HealthRecords hr){
        log.info("修改健康记录,hr:{}",hr);
        healthRecordsService.update(hr);
        return Result.success("修改成功");
    }

}
